// 全局变量与初始化加载
var allTabs = ['tab_1','tab_2','tab_3','tab_4','tab_5']; // TAB页全集
var dict = null; // 代码集
loadDictData(); //加载代码集


// 从代码集中获取数据
function getDictData(type){
	var result = '';
	dict.each(function(o){
		if(type == o['dicttype']){
			result = o['dictlist'];
		}
	});
	return result;
}

// 根据表单、字段、值获取对应名称
function getDictValue(form,column,value){
	var dictForm = Params.getDict()[form];
	if(null == dictForm || undefined == dictForm){
		return value;
	}                                
	var dictType = dictForm[column];//表单具有代码集的所有字段
	if(null == dictType || undefined == dictType){
		return value; // 返回原来值
	}
	var datas = getDictData(dictType);
	for(var i = 0;i < datas.length; i++){
		if(datas[i]['dictcode'] == value){
			return datas[i]['dictname'];
		}
	}
	return value;
}

// 保存不同表单信息
function saveForm(formId){
	var bean = getFormBean(formId);
	bean.pid = pid; // 题录主键
	var refrence = Params.getTableRefrence(formId);
	if(null != refrence){ // 补充外键
		var fkid = $('#'+refrence[1]).find('input[name="id"]').val()
		if(null == fkid || '' == fkid || undefined == fkid){
			alert('请先选中或创建一条【' + Params.saveWarn[refrence[1]]+'】');
			return;
		}
		bean[refrence[0]] = fkid;
	}
	switch(formId){
		case "syqk": 
			if(!checkSyqkForm()) return;
			produceHelper.saveOrUpdateShiyanqk(bean,formId,saveOrUpdateCallback);break; // 实验情况信息
		case "jsff": 
			if(!checkJsffForm()) return;
			produceHelper.saveOrUpdateJishuff(bean,formId,saveOrUpdateCallback);break; // 技术方法信息
		case "ylzy": 
			if(!(checkYlzyForm())) return;
			produceHelper.saveOrUpdateYaolizy(bean,formId,saveOrUpdateCallback);break; // 方剂-中药-组分药理作用信息
		case "sylxzb":
			if(!checkSylxzbForm()) return;
			bean.rtype='1';produceHelper.saveOrUpdateLiaoxiaozb(bean,formId,saveOrUpdateCallback);break; // 实验疗效指标信息
		case "linchuang":
			if(!checkLinchuangForm()) return;
			produceHelper.saveOrUpdateLinchuanggc(bean,formId,saveOrUpdateCallback);break; // 临床观察信息
		case "lhyy":
			if(!checkLhyyForm()) return;
			produceHelper.saveOrUpdateLianheyy(bean,formId,saveOrUpdateCallback);break; // 联合用药信息
		case "blfyxx": 
			if(!checkBlfyxxForm()) return;
			produceHelper.saveOrUpdateBuliangfyxx(bean,formId,saveOrUpdateCallback);break; // 不良反应信息
		case "lxzb": 
			if(!checkLxzbForm()) return;
			bean.rtype='2';produceHelper.saveOrUpdateLiaoxiaozb(bean,formId,saveOrUpdateCallback);break; // 疗效指标信息
		case "lcdz": 
			if(!checkLcdzForm()) return;
			produceHelper.saveOrUpdateLinchuangdz(bean,formId,saveOrUpdateCallback);break; // 临床对照信息
		case "hxcf": 
			if(!checkHxcfForm()) return;
			bean.rtype='1';produceHelper.saveOrUpdateCdcHuoxingcf(bean,formId,saveOrUpdateCallback);break; // 组分-部位-（活性）成分
		case "zycy": 
			if(!checkZycyForm()) return;
			produceHelper.saveOrUpdateZhongyaocy(bean,formId,saveOrUpdateCallback);break; // 中药成药信息
		case "zyzz": 
			if(!checkZyzzForm()) return;
			produceHelper.saveOrUpdateZhongyaozz(bean,formId,saveOrUpdateCallback);break; // 中药组成信息
		case "zblfybd": 
			if(!checkZblfybdForm()) return;
			bean.rtype='2';produceHelper.saveOrUpdateBulianfybd(bean,formId,saveOrUpdateCallback);break; // 不良反应报道
		case "zhxcf": 
			if(!checkZhxcfForm()) return;
			bean.rtype='2';produceHelper.saveOrUpdateCdcHuoxingcf(bean,formId,saveOrUpdateCallback);break; // 组分-部位-（活性）成分
		case "blfybd": 
			if(!checkBlfybdForm()) return;
			bean.rtype='1';produceHelper.saveOrUpdateBulianfybd(bean,formId,saveOrUpdateCallback);break; // 不良反应报道
		default: break;
	}
}

//保存返回提示
function saveOrUpdateCallback(data){
	//预备数据
	var obj = eval('(' + data + ')');
	var array = obj.beans;
	var operator = obj.operator;
	var formId = obj.formid;
	$('#'+formId).find('input[name="id"]').val(array[0].id);
	var cells = Params.getCells(formId);
	if("1" == operator){// 增加操作
		addRows(formId,array,operator);
	}else if("2" == operator){// 修改操作
		$('#t'+formId).find('tr').each(function(){
			if($(this).find(':radio:checked').size() > 0){
				var cells = Params.getCells(formId);
				for(var i = 0;i < cells.length; i++){
					var result = getDictValue(formId,cells[i],array[0][cells[i]]);
					$(this).find('td').eq(i+1).attr('title',result);
					$(this).find('td').eq(i+1).html(result);
					
				}
			}
		});
	}
	alert(obj.msg);
}

//封装对象
function getFormBean(formId){
	var bean = {};
	var $container = $('#'+formId).find('.tableForm');
	$(':input:hidden,:password,:text',$container).each(function(){
		var $value = $(this).val();
		if(null != $value && "" != $value){
			bean[$(this).attr('name')] = $value;
		}
	});
	$(':input:checked',$container).each(function(){
		var $value = $(this).val();
		if(null != $value && "" != $value){
			bean[$(this).attr('name')] = $value;
		}
	});
	$('select',$container).each(function(){
		var $value = $(this).find('option:selected').val();
		if(null != $value && "" != $value){
			bean[$(this).attr('name')] = $value;
		}
	});
	return bean;
}

// 依次加载Tab数据
function loadTabData(tabs){
	// 预先发起首个TAB请求
	var firstTab = tabs.shift();
	var MFormId = Params.getMainForm(firstTab);
	selectMainFormData(MFormId);
	
	// 加载其他TAB
	tabs.each(function(tab){
		var MFormId = Params.getMainForm(tab);
		selectMainFormData(MFormId);
	});
}

//加载主列表数据
function selectMainFormData(formId){
	produceHelper.getObjectListByRefrence(formId,pid,selectDataCallback);
}

//选择附加表数据
function selectAttachFormData(formId,fkid){
	produceHelper.getObjectListByFK(formId,pid,fkid,selectDataCallback);
}

// 加载数据回调函数
function selectDataCallback(data){
	var obj = eval('(' + data + ')');
	var array = obj.beans;
	var formId = obj.formid;
	addRows(formId,array);
}

// 根据数据表格中插入行
function addRows(formId,array,operator){
	if(array.length == 0){
		return;
	}
	//预备处理函数
	var cellFuncs = new Array();
	var radioFunc = function(data){
		return '<input name="s'+formId+'" type="radio" value="'+data.id+'" onchange="selectOneRow(this,\''+formId+'\','+data.id+');" onclick="this.blur();"/>';
	};
	var cells = Params.getCells(formId);
	cellFuncs.push(radioFunc);
	for(var i = 0;i < cells.length;i++){
		var func = function(data){
			var column = cells[index++ % cells.length]; //列名
			var value = data[column]; // 当前值
			var codeValue = null; //代码集类型
			var result = getDictValue(formId,column,value);
			return result;
		};
 	cellFuncs.push(func);
	}
	var delFunc = function(data){
		return '<li class="delOper" data="'+data.id+'" onclick="deleteOneRow(\''+formId+'\','+data.id+');">删除</li>';
	};
	cellFuncs.push(delFunc);
	//增加数据
	var index = 0;
	DWRUtil.addRows("t"+formId, array , cellFuncs, {
		cellCreator: function(options){
			var td = document.createElement("td");
			if(options.cellNum == 0 || options.cellNum == (cells.length + 1)){
 				td.className = "tac";
			}
			if(options.cellNum > 0 && options.cellNum <= cells.length){
				var result = getDictValue(formId,cells[(index - 1) % cells.length],options.rowData[cells[(index - 1) % cells.length]]);
				td.title = result;
			}
			return td;
		},
		escapeHtml:false 
	});
	if("1" == operator){
		var length = $('#'+formId).find('.tableList input:radio').size() - 1;
		$('#'+formId).find('.tableList input:radio:eq('+length+')').trigger('click').trigger('change');
	}else{
		$('#'+formId).find('.tableList input:radio:eq(0)').trigger('click').trigger('change');
	}
}

//选中一行
function selectOneRow(radio,formId,selfId){
	if(radio.checked){
		produceHelper.getObjectByPK(formId,selfId,fillFormCallback);
	}
}

// 响应值填充FORM
function fillFormCallback(data){
	var obj = eval('(' + data + ')');
	var array = obj.beans;
	var formId = obj.formid;
	var result = array[0];
	var $container = $('#'+formId).find('.tableForm');
	
	$('input:hidden,:text,textarea',$container)
	.not(':button,:submit,:reset')
	.each(function(){
		$(this).val(result[$(this).attr('name')]);
	});
	
	$('select',$container)
	.each(function(){
		var selected = $(this).find('option[value="'+result[$(this).attr('name')]+'"]');
		var id = $(this).attr('id');
		$('#selectinputname' + id).val(selected.text());
		selected.attr("selected",true);
	});
	// 加载附表数据
	var forms = Params.getAttachForm(formId);
	if(null != forms){
		forms.each(function(AttForm){
			clearArea(AttForm);
			selectAttachFormData(AttForm, result.id);
		});
	}
}

// 删除一行
function deleteOneRow(formId,pkid){
	if(window.confirm("确定删除？")){
		produceHelper.deleteOneRowData(formId,pkid,pid,deleteOneRowCallback);
	}
}

// 删除一行回调
function deleteOneRowCallback(data){
	var obj = eval('(' + data + ')');
	var formId = obj.formid;
	var mainTbls = Params.getMainTable();
	clearArea(formId);
	if(mainTbls.contains(formId)){ // 删除主表
		var forms = Params.getAttachForm(formId);
		if(null != forms){
			forms.each(function(attachForm){
				clearArea(attachForm);
			});
		}
		selectMainFormData(formId);
	}else {
		var fkform = Params.getFKFormName(formId);
		selectAttachFormData(formId, $('#'+fkform).find('input[name="id"]').val());
	}
	alert(obj.msg);
}

// 清空区域
function clearArea(formId){
	DWRUtil.removeAllRows("t"+formId);
	$(':input','#'+formId)
	 .not(':button, :submit, :reset') 
	 .val('')
	 .removeAttr('checked')  
	 .removeAttr('selected');
}


// 加载字典数据
function loadDictData(){
	DWREngine.setAsync(false);
	var dictcode = ['3','4','5','6','7','8','9','11','12','13','14','15','16','17','18','19'];
	produceHelper.getDictData(dictcode,loadDictCallback);
}

// 加载字典数据回调
function loadDictCallback(data){
	//alert(data);
	dict = eval('(' + data + ')');
	DWREngine.setAsync(true);
}

// 未表单SELECT增加下拉
function FillOptions(formId,name,datas){
	if(null == datas || undefined == datas){
		return;
	}
	var $select = $('#' + formId).find('.tableForm').find('select[name="'+name+'"]');
	$select.each(function(){
		if(this.tagName == "SELECT"){
			select = this;
	   	 	var option = new Option('','');
	   		select.options.add(option);
			$.each(datas,function(i,n){
		   	 	option = new Option(eval("n.dictname"),eval("n.dictcode"));
		   		select.options.add(option);
			});
		}
	});
}

// 参数
var Params = {
	// 保存提示
	saveWarn : {
		'syqk' : '实验情况信息',
		'zycy' : '中药成药信息',
		'linchuang' : '临床观察信息'
	},
	// 各表单字典映射
	dict : {
		'syqk' : {
			'sydxlx' : '3'
		},
		'jsff' : {
			'syfflx' : '12',
			'syffmc' : '13'
		},
		'sylxzb' : {
			'zblx' : '6'
		},
		'blfybd' : {
			'geiyaofs' : '15',
			'buliangfyfl' : '17',
			'buliangfyyy' : '18'
		},
		'ylzy' : {
			'ylzylx' : '4',
			'ylzy' : '5',
			'yddlx' : '19'
		},
		'zycy' : {
			'geiyfs' : '15',
			'jixing' : '16'
		},
		'zyzz' : {
			'herbunit' : '14'
		},
		'zblfybd' : {
			'geiyaofs' : '15',
			'buliangfyfl' : '17',
			'buliangfyyy' : '18'
		},
		'zhxcf' :{
			'zufenlx' : '7',
			'tiquff' : '8',
			'fenliff' : '9',
			'zufencdff' : '11'
		},
		'blfyxx' : {
			'bulfylx' : '17'
		},
		'lxzb' : {
			'zblx' : '6'
		},
		'hxcf' : {
			'zufenlx' : '7',
			'tiquff' : '8',
			'fenliff' : '9',
			'zufencdff' : '11'
		}
	},
	// 填充表格字段描述
	cells : { 
		'syqk' : ['sydxlx','sydx','memo'], // 实验情况信息
		'jsff':   ['syfflx','syffmc'], // 技术方法信息
	    'sylxzb': ['zblx','zbmc','memo'],// 疗效指标信息
		'ylzy':   ['ylzy','dxcw'], // 方剂-中药-组分药理作用信息
		'zycy':   ['zycymc','jixing','laiyuan','yfyl','geiyfs'], // 中药成药信息
		'zyzz':   ['herbname','herbcount','herbunit'], // 中药组成信息
		'zblfybd': ['yapwcj','zhiliaobz','geiyaofs','yongfyl'], // 不良反应报道
		'zhxcf':   ['bianhao','zufenmc','zufenlx','zufencdff','zufenhl'], // 组分-部位-（活性）成分
		'blfybd': ['yapwcj','zhiliaobz','geiyaofs','yongfyl'], // 不良反应报道
		'linchuang':  ['yanjff','zhiljb','yanjiucount','yanjiuyy'], // 临床观察信息
		'lcdz':   ['groupstr','bingls','dzyw','youxl','bulfy'], // 临床对照信息
		'blfyxx': ['bulfylx','bulfybx','blfyclff'], // 不良反应信息
		'lxzb':   ['zblx','zbmc','memo'], // 疗效指标信息
		'lhyy':   ['ywmc','memo'], // 联合用药信息
		'hxcf':   ['bianhao','zufenmc','zufenlx','zufencdff','zufenhl'] // 组分-部位-（活性）成分
	},
	// 附加表填充外键
	tableRefrence : {
		'jsff':   ['syid','syqk'], // 技术方法信息
		'ylzy':   ['syid','syqk'], // 方剂-中药-组分药理作用信息
		'sylxzb': ['rid','syqk'], // 方剂-中药-组分药理作用信息
		
		'zyzz':   ['zycyid','zycy'], // 中药组成信息
		'zblfybd':   ['rid','zycy'],
		'zhxcf':   ['rid','zycy'],
		
		'lcdz':   ['lcid','linchuang'], // 临床对照信息
		'blfyxx': ['lcid','linchuang'], // 不良反应信息
		'lxzb':   ['rid','linchuang'], // 疗效指标信息
		'lhyy':   ['lcid','linchuang'] // 联合用药信息
	},
	// 主题药物类型决定打开的TAB
	themeDrugTab : {
		'1' :  ['tab_2','tab_3','tab_5'], //中成药
		'2' :  ['tab_2','tab_3','tab_5'], //方剂
		'3' :  ['tab_2','tab_3','tab_5'], //单味药
		'4' :  ['tab_5'] //活性组分
	},
	// 文献类型决定打开的TAB
	documentTab : {
		'1' :  ['tab_4'], //临床试验
		'2' :  ['tab_3'], //不良反应报道
		'3' :  ['tab_1'], //动物试验
		'4' :  ['tab_1'], //药理
		'5' :  ['tab_1'], //药代
		'6' :  ['tab_1'] //药物化学
	},
	// 主表
	mainTable : ['syqk','zycy','blfybd','linchuang','hxcf'],
	// Tab决定加载数据对应主表
	mainForm : {
		'tab_1' :  'syqk',
		'tab_2' :  'zycy',
		'tab_3' : 'blfybd',
		'tab_4' :  'linchuang',
		'tab_5' :  'hxcf'
	},
	// 主表决定加载数据附表
	attachForm : {
		'syqk' :  ['jsff','sylxzb','ylzy'],
		'zycy' :  ['zyzz','zblfybd','zhxcf'],
		'blfybd' :  null,
		'linchuang' :  ['lcdz','blfyxx','lxzb','lhyy'],
		'hxcf' :  null
	},
	// 上下TAB对照
	cascadeTab : {
		'tab_1' :  'one',
		'tab_2' :  'two',
		'tab_3' :  'three',
		'tab_4' :  'four',
		'tab_5' :  'five'
	},
 	getCells : function(formId){
 		return this.cells[formId];
 	},
 	getTableRefrence : function(formId){
 		return this.tableRefrence[formId];
 	},
 	getTabs : function(themeType,documentType){
 		return allTabs;
 		/*var themeTabs = this.themeDrugTab[themeType];
 		var documentTabs = this.documentTab[documentType];
 		var result = themeTabs.concat(documentTabs).uniquelize().sort();
 		var hiddenTabs = Array.minus(allTabs,result);
 		hiddenTabs.each(function(o){
 			$('#'+o).hide();
 		})*/;
 		return result;
 	},
 	getCascadeTab : function(tabId){
 		return this.cascadeTab[tabId];
 	},
 	getMainTable : function(){
 		return this.mainTable;
 	},
 	getMainForm : function(tabId){
 		return this.mainForm[tabId];
 	},
 	getAttachForm : function(main){
 		return this.attachForm[main];
 	},
 	getDict : function(){
 		return this.dict;
 	},
 	getFKFormName :function(formid){
 		if("jsff" == formid || "sylxzb" == formid || "ylzy" == formid){
 			return "syqk";
 		}else if("zyzz" == formid || "zblfybd" == formid || "zhxcf" == formid){
 			return "zycy";
 		}else if("lcdz" == formid || "blfyxx" == formid || "lxzb" == formid || "lhyy" == formid){
 			return "linchuang";
 		}
 	}
};

/*******************表单校验****************************/

function checkSyqkForm(){
	var $form = $('#syqk');
	var $sydxlx = $form.find('#selectinputnames_sydxlx');
	var $sydx = $form.find('input[name="sydx"]');
	var $memo = $form.find('input[name="memo"]');
	
	if(isNull($sydxlx.val()) && isNull($sydx.val()) && isNull($memo.val())){
		alert("表单不能全部为空");
		$sydxlx.focus();
		return false;
	}
	//if(isNull($sydxlx.val())){alert('实验对象类型不能为空'); $sydxlx.focus(); return false;}
	//if(isNull($sydx.val())){alert('实验对象不能为空'); $sydx.focus();return false;}
	return true;
}

function checkJsffForm(){
	var $form = $('#jsff');
	var $syfflx = $form.find('#selectinputnames_syfflx');
	var $syffmc = $form.find('#selectinputnames_syffmc');
	var $memo = $form.find('input[name="memo"]');
	
	if(isNull($syfflx.val()) && isNull($syffmc.val()) && isNull($memo.val())){
		alert("表单不能全部为空");
		$syfflx.focus();
		return false;
	}
	//if(isNull($syfflx.val())){alert('实验方法类型不能为空'); $syfflx.focus(); return false;}
	//if(isNull($syffmc.val())){alert('实验方法名称不能为空'); $syffmc.focus();return false;}
	return true;
}

function checkYlzyForm(){
	var $form = $('#ylzy');
	var ylzy = $form.find('#selectinputnames_ylzy');
	var yddlx = $form.find('#selectinputnames_yddlx');
	var zyjz = $form.find('input[name="zyjz"]');
	var blfyjl = $form.find('input[name="blfyjl"]');
	var dxcw = $form.find('input[name="dxcw"]');
	var yddlxcs = $form.find('input[name="yddlxcs"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(ylzy.val()) && isNull(yddlx.val()) && isNull(zyjz.val()) 
		&& isNull(blfyjl.val()) && isNull(yddlxcs.val()) && isNull(dxcw.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		ylzy.focus();
		return false;
	}
	//if(isNull(ylzy.val())){alert('药理作用不能为空'); ylzy.focus(); return false;}
	//if(isNull(ylzylx.val())){alert('药理作用类型不能为空'); ylzylx.focus();return false;}
	//if(isNull(yddlx.val())){alert('药代动力学信息不能为空'); yddlx.focus(); return false;}
	//if(isNull(zyjz.val())){alert('作用机制不能为空'); zyjz.focus(); return false;}
	//if(isNull(blfyjl.val())){alert('不良反应记录不能为空'); blfyjl.focus(); return false;}
	//if(isNull(dxcw.val())){alert('代谢产物名称不能为空'); dxcw.focus(); return false;}
	return true;
}

function checkSylxzbForm(){
	var $form = $('#sylxzb');
	var zblx = $form.find('#selectinputnames_zblx_1');
	var zbmc = $form.find('input[name="zbmc"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(zblx.val()) && isNull(zbmc.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		zblx.focus();
		return false;
	}
	//if(isNull(zblx.val())){alert('指标类型不能为空'); zblx.focus(); return false;}
	//if(isNull(zbmc.val())){alert('指标名称不能为空'); zbmc.focus();return false;}
	return true;
}

function checkZycyForm(){
	var $form = $('#zycy');
	var zycymc = $form.find('input[name="zycymc"]');
	var zblx = $form.find('#selectinputnames_jixing');
	var laiyuan = $form.find('input[name="laiyuan"]');
	var yfyl = $form.find('input[name="yfyl"]');
	var geiyfs = $form.find('input[name="geiyfs"]');
	var lincsyz = $form.find('input[name="lincsyz"]');
	var gongnzz = $form.find('input[name="gongnzz"]');
	var fangjie = $form.find('input[name="fangjie"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(zycymc.val()) && isNull(zblx.val()) && isNull(laiyuan.val()) && isNull(yfyl.val())
		&& isNull(geiyfs.val()) && isNull(lincsyz.val()) && isNull(gongnzz.val()) && isNull(fangjie.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		zycymc.focus();
		return false;
	}
	
	//if(isNull(zycymc.val())){alert('名称不能为空'); zycymc.focus(); return false;}
	//if(isNull(zblx.val())){alert('剂型不能为空'); zblx.focus();return false;}
	//if(isNull(laiyuan.val())){alert('来源不能为空'); laiyuan.focus();return false;}
	//if(isNull(yfyl.val())){alert('用法用量不能为空'); yfyl.focus();return false;}
	//if(isNull(geiyfs.val())){alert('给药方式不能为空'); geiyfs.focus();return false;}
	//if(isNull(lincsyz.val())){alert('临床适应症不能为空'); lincsyz.focus();return false;}
	//if(isNull(gongnzz.val())){alert('功能主治不能为空'); gongnzz.focus();return false;}
	//if(isNull(fangjie.val())){alert('方解不能为空'); fangjie.focus();return false;}
	return true;
}

function checkZyzzForm(){
	var $form = $('#zyzz');
	var herbname = $form.find('input[name="herbname"]');
	var herbcount = $form.find('input[name="herbcount"]');
	var s_herbunit = $form.find('#selectinputnames_herbunit');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(herbname.val()) && isNull(herbcount.val()) && isNull(s_herbunit.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		herbname.focus();
		return false;
	}
	//if(isNull(herbname.val())){alert('中药名称不能为空'); herbname.focus(); return false;}
	//if(isNull(herbcount.val())){alert('中药剂量不能为空'); herbcount.focus();return false;}
	//if(isNull(s_herbunit.val())){alert('剂量单位不能为空'); s_herbunit.focus(); return false;}
	if(!isNull(herbcount.val()) && !isDecimal(herbcount.val())){alert('中药剂量必须为数字'); herbcount.focus(); return false;}
	return true;
}

function checkZblfybdForm(){
	var $form = $('#zblfybd');
	var yapwcj = $form.find('input[name="yapwcj"]');
	var zhiliaobz = $form.find('input[name="zhiliaobz"]');
	var geiyaofs = $form.find('#selectinputnames_geiyaofs_1');
	var yongfyl = $form.find('input[name="yongfyl"]');
	var bljbxinxi = $form.find('input[name="bljbxinxi"]');
	var guominzz = $form.find('input[name="guominzz"]');
	var tedian = $form.find('input[name="tedian"]');
	var buliangfyfl = $form.find('#selectinputnames_buliangfyfl_1');
	var buliangfyyy = $form.find('#selectinputnames_buliangfyyy_1');
	var buliangfyclff = $form.find('input[name="buliangfyclff"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(yapwcj.val()) && isNull(zhiliaobz.val()) && isNull(geiyaofs.val()) && isNull(yongfyl.val())
		&& isNull(bljbxinxi.val()) && isNull(buliangfyfl.val()) && isNull(buliangfyyy.val())
		&& isNull(buliangfyclff.val()) && isNull(guominzz.val()) && isNull(tedian.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		yapwcj.focus();
		return false;
	}
	
	//if(isNull(yapwcj.val())){alert('药物厂家不能为空'); yapwcj.focus(); return false;}
	//if(isNull(zhiliaobz.val())){alert('治疗病种不能为空'); zhiliaobz.focus();return false;}
	//if(isNull(geiyaofs.val())){alert('给药方式不能为空'); geiyaofs.focus(); return false;}
	//if(isNull(yongfyl.val())){alert('用法用量不能为空'); yongfyl.focus(); return false;}
	//if(isNull(bljbxinxi.val())){alert('病例基本信息不能为空'); bljbxinxi.focus();return false;}
	//if(isNull(buliangfyfl.val())){alert('原因分类不能为空'); buliangfyfl.focus(); return false;}
	//if(isNull(buliangfyyy.val())){alert('产生原因不能为空'); buliangfyyy.focus(); return false;}
	//if(isNull(buliangfyclff.val())){alert('处理方法不能为空'); buliangfyclff.focus();return false;}
	//if(!isNull(buliangfyfl.val()) && !isDecimal(buliangfyfl.val())){alert('原因分类必须为数字'); buliangfyfl.focus(); return false;}
	return true;
}

function checkZhxcfForm(){
	var $form = $('#zhxcf');
	var bianhao = $form.find('input[name="bianhao"]');
	var zufenmc = $form.find('input[name="zufenmc"]');
	var zufenlx = $form.find('#selectinputnames_zufenlx_1');
	var zufenhl = $form.find('input[name="zufenhl"]');
	var zufencdff = $form.find('#selectinputnames_zufencdff_1');
	var cedingzb = $form.find('input[name="cedingzb"]');
	var cedingzbhl = $form.find('input[name="cedingzbhl"]');
	var jianbff = $form.find('input[name="jianbff"]');
	var tiquff = $form.find('#selectinputnames_tiquff_1');
	var fenliff = $form.find('#selectinputnames_fenliff_1');
	var duizhaop = $form.find('input[name="duizhaop"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(bianhao.val()) && isNull(zufenmc.val()) && isNull(zufenlx.val()) && isNull(zufenhl.val())
		&& isNull(zufencdff.val()) && isNull(cedingzb.val()) && isNull(cedingzbhl.val()) && isNull(jianbff.val())
		&& isNull(jianbff.val()) && isNull(tiquff.val()) && isNull(fenliff.val()) && isNull(fenliff.val())
		&& isNull(duizhaop.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		bianhao.focus();
		return false;
	}
	
	//if(isNull(bianhao.val())){alert('编号不能为空'); bianhao.focus(); return false;}
	//if(isNull(zufenmc.val())){alert('组分名称不能为空'); zufenmc.focus();return false;}
	//if(isNull(zufenlx.val())){alert('组分类型不能为空'); zufenlx.focus(); return false;}
	//if(isNull(zufenhl.val())){alert('组分含量不能为空'); zufenhl.focus();return false;}
	//if(isNull(zufencdff.val())){alert('测定方法不能为空'); zufencdff.focus(); return false;}
	//if(isNull(cedingzb.val())){alert('测定指标不能为空'); cedingzb.focus();return false;}
	//if(isNull(cedingzbhl.val())){alert('测定指标含量不能为空'); cedingzbhl.focus(); return false;}
	//if(isNull(jianbff.val())){alert('鉴别方法不能为空'); jianbff.focus();return false;}
	//if(isNull(tiquff.val())){alert('提取方法不能为空'); tiquff.focus(); return false;}
	//if(isNull(fenliff.val())){alert('分离方法不能为空'); fenliff.focus();return false;}
	return true;
}

function checkBlfybdForm(){
	var $form = $('#blfybd');
	var yapwcj = $form.find('input[name="yapwcj"]');
	var zhiliaobz = $form.find('input[name="zhiliaobz"]');
	var geiyaofs = $form.find('#selectinputnames_geiyaofs');
	var yongfyl = $form.find('input[name="yongfyl"]');
	var bljbxinxi = $form.find('input[name="bljbxinxi"]');
	var guominzz = $form.find('input[name="guominzz"]');
	var tedian = $form.find('input[name="tedian"]');
	var buliangfyfl = $form.find('#selectinputnames_buliangfyfl');
	var buliangfyyy = $form.find('#selectinputnames_buliangfyyy');
	var buliangfyclff = $form.find('input[name="buliangfyclff"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(yapwcj.val()) && isNull(zhiliaobz.val()) && isNull(geiyaofs.val()) && isNull(yongfyl.val())
		&& isNull(bljbxinxi.val()) && isNull(buliangfyfl.val()) && isNull(buliangfyyy.val())
		&& isNull(buliangfyclff.val()) && isNull(guominzz.val()) && isNull(tedian.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		yapwcj.focus();
		return false;
	}
	//if(isNull(yapwcj.val())){alert('药物厂家不能为空'); yapwcj.focus(); return false;}
	//if(isNull(zhiliaobz.val())){alert('治疗病种不能为空'); zhiliaobz.focus();return false;}
	//if(isNull(geiyaofs.val())){alert('给药方式不能为空'); geiyaofs.focus(); return false;}
	//if(isNull(yongfyl.val())){alert('用法用量不能为空'); yongfyl.focus(); return false;}
	//if(isNull(bljbxinxi.val())){alert('病例基本信息不能为空'); bljbxinxi.focus();return false;}
	//if(isNull(buliangfyfl.val())){alert('原因分类不能为空'); buliangfyfl.focus(); return false;}
	//if(isNull(buliangfyyy.val())){alert('产生原因不能为空'); buliangfyyy.focus(); return false;}
	//if(isNull(buliangfyclff.val())){alert('处理方法不能为空'); buliangfyclff.focus();return false;}
	//if(!isNull(buliangfyfl.val()) && !isDecimal(buliangfyfl.val())){alert('原因分类必须为数字'); buliangfyfl.focus(); return false;}
	return true;
}

function checkLinchuangForm(){
	var $form = $('#linchuang');
	var yanjff = $form.find('input[name="yanjff"]');
	var zhiljb = $form.find('input[name="zhiljb"]');
	var yanjiucount = $form.find('input[name="yanjiucount"]');
	var yanjiuyy = $form.find('input[name="yanjiuyy"]');
	var youxl = $form.find('input[name="youxl"]');
	var zdbz = $form.find('input[name="zdbz"]');
	var lxbz = $form.find('input[name="lxbz"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(yanjff.val()) && isNull(zhiljb.val()) && isNull(yanjiucount.val()) && isNull(yanjiuyy.val())
		&& isNull(youxl.val()) && isNull(zdbz.val()) && isNull(lxbz.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		yanjff.focus();
		return false;
	}
	
	//if(isNull(yanjff.val())){alert('研究方法不能为空'); yanjff.focus(); return false;}
	//if(isNull(zhiljb.val())){alert('治疗疾病不能为空'); zhiljb.focus();return false;}
	//if(isNull(yanjiucount.val())){alert('研究例数不能为空'); yanjiucount.focus(); return false;}
	//if(isNull(yanjiuyy.val())){alert('研究医院不能为空'); yanjiuyy.focus();return false;}
	//if(isNull(youxl.val())){alert('有效率不能为空'); youxl.focus(); return false;}
	//if(isNull(zdbz.val())){alert('诊断标准不能为空'); zdbz.focus(); return false;}
	//if(isNull(lxbz.val())){alert('疗效标准不能为空'); lxbz.focus(); return false;}

	if(!isNull(yanjiucount.val()) && !isPositiveInt(yanjiucount.val())){alert('研究例数必须为整数'); yanjiucount.focus(); return false;}
	if(!isNull(youxl.val()) && !isDecimal(youxl.val())){alert('有效率必须为数字'); youxl.focus(); return false;}
	return true;
}

function checkLcdzForm(){
	var $form = $('#lcdz');
	var groupstr = $form.find('input[name="groupstr"]');
	var bingls = $form.find('input[name="bingls"]');
	var dzyw = $form.find('input[name="dzyw"]');
	var youxl = $form.find('input[name="youxl"]');
	var bulfy = $form.find('input[name="bulfy"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(groupstr.val()) && isNull(bingls.val()) && isNull(dzyw.val()) && isNull(youxl.val())
		&& isNull(bulfy.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		groupstr.focus();
		return false;
	}
	
	//if(isNull(groupstr.val())){alert('编号不能为空'); groupstr.focus(); return false;}
	//if(isNull(bingls.val())){alert('病例数不能为空'); bingls.focus();return false;}
	//if(isNull(dzyw.val())){alert('对照药物不能为空'); dzyw.focus(); return false;}
	//if(isNull(youxl.val())){alert('有效率不能为空'); youxl.focus();return false;}
	//if(isNull(bulfy.val())){alert('不良反应不能为空'); bulfy.focus(); return false;}

	if(!isNull(youxl.val()) && !isDecimal(youxl.val())){alert('有效率必须为数字'); youxl.focus(); return false;}
	if(!isNull(bingls.val()) && !isPositiveInt(bingls.val())){alert('病例数必须为整数'); bingls.focus(); return false;}
	return true;
}

function checkBlfyxxForm(){
	var $form = $('#blfyxx');
	var bulfylx = $form.find('#selectinputnames_bulfylx');
	var bulfybx = $form.find('input[name="bulfybx"]');
	var blfyclff = $form.find('input[name="blfyclff"]');
	var qtwenxianbd = $form.find('input[name="qtwenxianbd"]');
	var bulfy = $form.find('input[name="bulfy"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(bulfylx.val()) && isNull(bulfybx.val()) && isNull(blfyclff.val())
		&& isNull(qtwenxianbd.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		bulfylx.focus();
		return false;
	}
	
	//if(isNull(bulfylx.val())){alert('不良反应类型不能为空'); bulfylx.focus(); return false;}
	//if(isNull(bulfybx.val())){alert('不良反应表现不能为空'); bulfybx.focus();return false;}
	//if(isNull(blfyclff.val())){alert('不良反处理方法不能为空'); blfyclff.focus(); return false;}
	//if(isNull(qtwenxianbd.val())){alert('其它文献报道相关信息不能为空'); qtwenxianbd.focus();return false;}
	return true;
}

function checkLxzbForm(){
	var $form = $('#lxzb');
	var zblx = $form.find('#selectinputnames_zblx');
	var zbmc = $form.find('input[name="zbmc"]');
	var youxl = $form.find('input[name="youxl"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(zblx.val()) && isNull(zbmc.val()) && isNull(youxl.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		zblx.focus();
		return false;
	}
	//if(isNull(zblx.val())){alert('指标类型不能为空'); zblx.focus(); return false;}
	//if(isNull(zbmc.val())){alert('指标名称不能为空'); zbmc.focus();return false;}
	if(!isNull(youxl.val()) && !isDecimal(youxl.val())){alert('有效率必须为数字'); youxl.focus(); return false;}
	return true;
}

function checkLhyyForm(){
	var $form = $('#lhyy');
	var ywmc = $form.find('input[name="ywmc"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(ywmc.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		ywmc.focus();
		return false;
	}
	
	//if(isNull(ywmc.val())){alert('药物名称不能为空'); ywmc.focus();return false;}
	return true;
}

function checkHxcfForm(){
	var $form = $('#hxcf');
	var bianhao = $form.find('input[name="bianhao"]');
	var zufenmc = $form.find('input[name="zufenmc"]');
	var zufenlx = $form.find('#selectinputnames_zufenlx');
	var zufenhl = $form.find('input[name="zufenhl"]');
	var zufencdff = $form.find('#selectinputnames_zufencdff');
	var cedingzb = $form.find('input[name="cedingzb"]');
	var cedingzbhl = $form.find('input[name="cedingzbhl"]');
	var jianbff = $form.find('input[name="jianbff"]');
	var tiquff = $form.find('#selectinputnames_tiquff');
	var fenliff = $form.find('#selectinputnames_fenliff');
	var duizhaop = $form.find('input[name="duizhaop"]');
	var memo = $form.find('input[name="memo"]');
	
	if(isNull(bianhao.val()) && isNull(zufenmc.val()) && isNull(zufenlx.val()) && isNull(zufenhl.val())
		&& isNull(zufencdff.val()) && isNull(cedingzb.val()) && isNull(cedingzbhl.val())
		&& isNull(jianbff.val()) && isNull(tiquff.val()) && isNull(fenliff.val())
		&& isNull(duizhaop.val()) && isNull(memo.val())){
		alert("表单不能全部为空");
		bianhao.focus();
		return false;
	}
	
	//if(isNull(bianhao.val())){alert('编号不能为空'); bianhao.focus(); return false;}
	//if(isNull(zufenmc.val())){alert('组分名称不能为空'); zufenmc.focus();return false;}
	//if(isNull(zufenlx.val())){alert('组分类型不能为空'); zufenlx.focus(); return false;}
	//if(isNull(zufenhl.val())){alert('组分含量不能为空'); zufenhl.focus();return false;}
	//if(isNull(zufencdff.val())){alert('测定方法不能为空'); zufencdff.focus(); return false;}
	//if(isNull(cedingzb.val())){alert('测定指标不能为空'); cedingzb.focus();return false;}
	//if(isNull(cedingzbhl.val())){alert('测定指标含量不能为空'); cedingzbhl.focus(); return false;}
	//if(isNull(jianbff.val())){alert('鉴别方法不能为空'); jianbff.focus();return false;}
	//if(isNull(tiquff.val())){alert('提取方法不能为空'); tiquff.focus(); return false;}
	//if(isNull(fenliff.val())){alert('分离方法不能为空'); fenliff.focus();return false;}
	return true;
}